import { Application } from 'egg';
/**
 * @param {Egg.Application} app - egg application
 */
export default (app: Application) => {
  const { router, controller, passport } = app;
  const jwt = passport.authenticate('jwt', {
    session: false,
    successReturnToOrRedirect: undefined,
  });

  router.get('/homepage', jwt, controller.home.index);
  router.get('/manager/authorization', controller.manager.authorization);
  router.put('/manager', jwt, controller.manager.update);
  router.get('/template/list', jwt, controller.template.show);
  router.post('/template', jwt, controller.template.create);
  router.put('/template', jwt, controller.template.update);
  router.delete('/template', jwt, controller.template.delete);
  router.get('/template', jwt, controller.template.find);
  /** 获取 template 选项 */
  router.get('/template/optionList', jwt, controller.template.optionList);

  router.get('/questionnaire/list', jwt, controller.questionnaire.show);
  router.get('/questionnaire', jwt, controller.questionnaire.search);
  router.get('/questionnaire/templateDetail',
    controller.questionnaire.searchByQuestionnaireUuid);
  router.post('/questionnaire', jwt, controller.questionnaire.create);
  router.put(
    '/questionnaire/visible',
    jwt,
    controller.questionnaire.updateOptionVisible
  );
  router.put('/questionnaire', jwt, controller.questionnaire.update);
  router.delete('/questionnaire', jwt, controller.questionnaire.delete);
  /** 查看回答的问卷选项 */
  router.get(
    '/questionnaire/optionList',
    jwt,
    controller.questionnaire.searchForOption
  );
  /** 管理端查看问卷细节 */
  router.get('/questionnaire/managerDetail', jwt, controller.questionnaire.searchManagerDetail);

  router.get('/workUnit', jwt, controller.workUnit.show);
  router.get('/affiliated', jwt, controller.affiliatedUnit.show);
  router.get('/jobPosition', jwt, controller.jobPosition.show);
  router.get('/operatingPost', jwt, controller.operatingPost.show);
  router.delete('/workUnit', jwt, controller.workUnit.delete);
  router.delete('/affiliated', jwt, controller.affiliatedUnit.delete);
  router.delete('/jobPosition', jwt, controller.jobPosition.delete);
  router.delete('/operatingPost', jwt, controller.operatingPost.delete);
  router.post('/workUnit', jwt, controller.workUnit.create);
  router.post('/affiliated', jwt, controller.affiliatedUnit.create);
  router.post('/jobPosition', jwt, controller.jobPosition.create);
  router.post('/operatingPost', jwt, controller.operatingPost.create);
  router.put(
    '/questionnaire/switch',
    jwt,
    controller.questionnaire.updateSwitch
  );

  // 上传图片
  router.post(
    '/image',
    jwt,
    controller.file.upload
  );
  // 下载图片
  router.get(
    '/image',
    controller.file.viewPicture
  );

  // 短信发送
  router.get('/sms', controller.smsVerification.send);
  router.get('/sms/verify', controller.smsVerification.verify);

  router.get('/questionnaire/detail', controller.questionnaire.searchDetail);
  router.get('/user/answerProgressState', controller.user.answerProgressState);

  // 手动录入的用户手机号是否已存在
  router.get('/user/existTel', controller.user.existTel);

  // 用户信息存储
  router.put('/user/userInfo', controller.user.userInfo);
  // 获取用户基本信息。
  router.get(
    '/user/basicInfo',
    jwt,
    controller.user.basicInfo
  );

  // 回答问题
  router.post('/answer/saveQuestionScore', controller.answer.saveQuestionScore);
  // 下载反馈 docx
  router.get(
    '/answer/downloadFeedbackDocx',
    controller.answer.downloadFeedbackDocx
  );
  // 将反馈发送到邮件中
  router.post(
    '/answer/sendEmail',
    controller.answer.sendEmail
  );
  // 查询回答列表
  router.get(
    '/answer/list',
    controller.answer.searchList
  );
  router.get(
    '/answer/downloadExportExcel',
    controller.answer.downloadExcel
  );
  // 删除回答
  router.delete(
    '/answer',
    controller.answer.delete
  );
  // 查询单个用户的分数数组
  router.get(
    '/answer/scoreList',
    controller.answer.scoreList
  );
  // 手动录入保存
  router.post(
    '/answer/saveManualOperation',
    jwt,
    controller.answer.saveManualOperation
  );
  // 查询问卷四个基本属性列表
  router.get(
    '/questionnaire/basicOptionList',
    jwt,
    controller.questionnaire.basicOptionList
  );

  // 问卷反馈页面化
  router.get(
    '/answer/feedback',
    controller.answer.feedback
  );
};
